local juxia = fk.CreateSkill {
  name = "juxia",
}

juxia:addEffect(fk.TargetConfirmed, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from and data.from ~= player and
      #table.filter(data.from.player_skills, function(skill)
        return skill:isPlayerSkill(data.from)
      end) > #table.filter(player.player_skills, function(skill)
        return skill:isPlayerSkill(player)
      end) and
      player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    return room:askForSkillInvoke(data.from, self.name, nil, "#juxia-invoke:"..player.id.."::"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    if data.card.sub_type == Card.SubtypeDelayedTrick then  --延时锦囊就取消掉？-_-||
      data:cancelTarget(player)
    else
      table.insertIfNeed(data.nullifiedTargets, player)
    end
    player:drawCards(2, self.name)
  end,
})

return juxia